/**
*      author: Y_Yao
*      created: 2025-04-05 14:08:33
**/

#include<bits/stdc++.h>

#define int LL
using namespace std;
using LL = long long;
const LL LLINF = 9e18;
const int INF = 0x3f3f3f3f;
const int N = 100 + 7;
int n;
int a[N];
map<int,int> cnt;
set<int> s;

void solve()
{
    cin >> n;
    int sum = 0;
    int mx = -INF;
    int mi = INF;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
        s.insert(a[i]);
        if(cnt[a[i]] == 0) sum += a[i];
        cnt[a[i]]++;
        mx = max(mx,a[i]);
        mi = min(mi,a[i]);
    }
    // cout << mx << " " << mi << endl;
    int ans = INF;
    for(int k = mi;k <= mx;k++)
    {
        int cur = 0;
        for(int i = 1;i <= n;i++)
        {
            cur += (k - a[i]) * (k - a[i]);
        }
        ans = min(ans,cur);
    }
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    // cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}